From a29e10dd0b5f0b785e6389d71dc9847a51307246 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Tue, 18 Oct 2016 16:55:26 +0100 Subject: [PATCH] x86/emul: Implement the STAC and CLAC instructions Note that unlike most privilege restricted instructions, STAC and CLAC are documented to raise #UD rather than #GP[0], and indeed do so. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- xen/arch/x86/x86_emulate/x86_emulate.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emulate/x86_emulate.c index fe055cff8b..43c4a9d4b6 100644 --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -1295,6 +1295,7 @@ static bool vcpu_has( #define vcpu_has_bmi1() vcpu_has( 7, EBX, 3, ctxt, ops) #define vcpu_has_hle() vcpu_has( 7, EBX, 4, ctxt, ops) #define vcpu_has_rtm() vcpu_has( 7, EBX, 11, ctxt, ops) +#define vcpu_has_smap() vcpu_has( 7, EBX, 20, ctxt, ops) #define vcpu_must_have(feat) \ generate_exception_if(!vcpu_has_##feat(), EXC_UD) @@ -4354,6 +4355,17 @@ x86_emulate( switch( modrm ) { + case 0xca: /* clac */ + case 0xcb: /* stac */ + vcpu_must_have(smap); + generate_exception_if(lock_prefix || vex.pfx || !mode_ring0(), + EXC_UD); + + _regs.eflags &= ~EFLG_AC; + if ( modrm == 0xcb ) + _regs.eflags |= EFLG_AC; + goto no_writeback; + #ifdef __XEN__ case 0xd1: /* xsetbv */ { -- 2.30.2